/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package backing;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import model.CurrentUser;
import officeboost.domain.VenueService;
import officeboost.domain.equip_venue.Venue;

/**
 *
 * @author XJ
 */
@ManagedBean
public class LocationBacking extends AbstractBacking{
   @EJB
   private VenueService venueService;
   private String venuename;
   private String month;
   private String day;
   private String startHour;
   private String startMin;
   private String endHour;
   private String endMin;
   private String message;
   private List<Venue> venueList=new ArrayList<>();

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getEndHour() {
        return endHour;
    }

    public void setEndHour(String endHour) {
        this.endHour = endHour;
    }

    public String getEndMin() {
        return endMin;
    }

    public void setEndMin(String endMin) {
        this.endMin = endMin;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getStartHour() {
        return startHour;
    }

    public void setStartHour(String startHour) {
        this.startHour = startHour;
    }

    public String getStartMin() {
        return startMin;
    }

    public void setStartMin(String startMin) {
        this.startMin = startMin;
    }

    public String getVenuename() {
        return venuename;
    }

    public void setVenuename(String venuename) {
        this.venuename = venuename;
    }

    public List<Venue> getVenueList() {
        return venueList;
    }

    public void setVenueList(List<Venue> venueList) {
        this.venueList = venueList;
    }
   
    public void init(){
        if(venueService.findAll()!=null)
            this.setVenueList(venueService.findAll());
    }
    
    public String venueBook(){
         
        CurrentUser cu=(CurrentUser)getSessionMap().get("currentUser");
        Date start=new Date(2012,Integer.parseInt(this.month),Integer.parseInt(this.day),Integer.parseInt(this.startHour),Integer.parseInt(this.startMin));
        Date end=new Date(2012,Integer.parseInt(this.month),Integer.parseInt(this.day),Integer.parseInt(this.endHour),Integer.parseInt(this.endMin));
        
        if(venueService.checkIfCanBeBooked(cu.getUsername(), this.venuename, start, end))
            this.setMessage("The room you booking is available: booking success");
        else
            this.setMessage("The room you booking is unavailable: booking failed");
        return "location_apply";
    }
}
